#include "bsp_key.h"

void bsp_InitKey(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Pin = KEY1_PIN | KEY2_PIN | KEY3_PIN;
    GPIO_Init(KEY1_PORT, &GPIO_InitStructure);
}

// check if key1 pressed
uint8_t bsp_IsKey1Pressed(void)
{
    uint8_t ret = 0;

    if(!GPIO_ReadInputDataBit(KEY1_PORT, KEY1_PIN)) {
        ret = 1;
    }else {
        ret = 0;
    }

    return ret;
}

// check if key2 pressed
uint8_t bsp_IsKey2Pressed(void)
{
    uint8_t ret = 0;

    if(!GPIO_ReadInputDataBit(KEY2_PORT, KEY2_PIN)) {
        ret = 1;
    }else {
        ret = 0;
    }

    return ret;
}

// check if key3 pressed
uint8_t bsp_IsKey3Pressed(void)
{
    uint8_t ret = 0;

    if(!GPIO_ReadInputDataBit(KEY3_PORT, KEY3_PIN)) {
        ret = 1;
    }else {
        ret = 0;
    }

    return ret;
}


